package bid.yanhj.yanhaijiang.listview;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 数据来源确定
 * 简单
 *
 */
public class MainActivity extends AppCompatActivity {

    private ListView mainLv;
//    private String[] data = new String[19];

    private List<Map<String, Object>> data;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mainLv = this.<ListView>findViewById(R.id.main_lv);

//        1 ArrayAdapter
//        for (int i = 0; i < 19; i++) {
//            data[i] = "yanhj - " + i;
//        }
//
//        // 最简单 绝对内容的类型
//        ArrayAdapter arrayAdapter =
//                new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,data);
//        // 绑定适配器
//        mainLv.setAdapter(arrayAdapter);

        // 2
        data = new ArrayList<>();

        for (int i = 0; i < 100; i++) {
            HashMap<String, Object> info = new HashMap<>();
            info.put("img", R.mipmap.ic_launcher);
            info.put("title", "这是标题" + i);
            data.add(info);
        }

        SimpleAdapter simpleAdapter =
                new SimpleAdapter(this, data,
                        R.layout.item_main,
                        new String[]{"img", "title"},
                        new int[]{R.id.item_iv, R.id.item_tv});

        mainLv.setAdapter(simpleAdapter);
    }
}
